import pymysql


class MysqlDB:
    def __init__(self, host="211.103.136.244", port=7061, user="student", password="iHRM_student_2021",
                 database="ihrm"):
        self.connection = pymysql.connect(host=host, port=port, user=user, password=password, database=database,
                                          charset='utf8')
        self.cursor = self.connection.cursor()

    def disconnect_db(self):
        self.cursor.close()
        self.connection.close()

    def query_data(self, sql_format, params):
        rows_num = self.cursor.execute(sql_format, params)
        data_collection = self.cursor.fetchall()
        self.connection.commit()
        return rows_num, data_collection

if __name__ == '__main__':
    mysql_db = MysqlDB()
    sql_format = "select * from bs_user where mobile=%s"
    data = mysql_db.query_data(sql_format=sql_format, params=13079543331)
    print(data)

    sql_format = "delete from bs_user where mobile=%s"
    data = mysql_db.query_data(sql_format=sql_format, params=13079543331)
    print(data)

    sql_format = "select * from bs_user where mobile=%s"
    data = mysql_db.query_data(sql_format=sql_format, params=13079543331)
    print(data)

    mysql_db.disconnect_db()
